Fix global query server crash when filter or validate throws null#5945
Open
vamsi2246 wants to merge 2 commits intoapache:mainfrom
Open
Fix global query server crash when filter or validate throws null#5945vamsi2246 wants to merge 2 commits intoapache:mainfrom
vamsi2246 wants to merge 2 commits intoapache:mainfrom
Conversation
When a filter or validate function throws null, the global event loop in loop.js unsafely tries to access its properties, crashing couchjs. This adds safe null checks to the global handler to prevent complete denial of service.
833f4d3 to
e6ebc65
Compare
Member
|
our pull request template is not optional. |
Author
|
Thanks for letting me know. I've updated the pull request description to use the standard template. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR fixes a critical unhandled exception bug in the global query server event loop (
loop.js).If a user document filter function throws
nullorundefined, the unhandlednullbubbles up directly tohandleError(e)inloop.js. This function immediately accessese[0], throwing aTypeError: Cannot read properties of null. BecausehandleErrorhas no error boundary of its own, this completely crashes thecouchjsOS process, failing the query system.A similar unsafe pattern exists in
validate.js.This patch adds explicit null checks to the global event handler, preventing arbitrary null exceptions from causing a full
couchjsdenial-of-service, ensuring they are properly returned as error messages over JSON instead.Testing recommendations
These changes can be tested by creating a design document with a filter function that explicitly throws
null, and observing that the query server gracefully returns an error message rather than crashing thecouchjsprocess.Related Issues or Pull Requests
None
Checklist
rel/overlay/etc/default.inisrc/docsfolder